package com.tms.project.tms.record.controller;

import java.util.List;

import com.tms.framework.web.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.tms.framework.aspectj.lang.annotation.Log;
import com.tms.framework.aspectj.lang.enums.BusinessType;
import com.tms.project.tms.record.domain.TeacherRecord;
import com.tms.project.tms.record.service.ITeacherRecordService;
import com.tms.framework.web.domain.AjaxResult;
import com.tms.common.utils.poi.ExcelUtil;
import com.tms.framework.web.page.TableDataInfo;

/**
 * 教师档案管理Controller
 *
 * @author xyl
 * @date 2021-03-22
 */
@Controller
@RequestMapping("/tms/record")
public class TeacherRecordController extends BaseController {
    private String prefix = "tms/record";

    @Autowired
    private ITeacherRecordService teacherRecordService;

    @RequiresPermissions("tms:record:view")
    @GetMapping()
    public String record() {
        return prefix + "/record";
    }

    /**
     * 报告详情页面
     */
    @GetMapping("/detail/{teacherRecordId}")
    public String detail(@PathVariable("teacherRecordId") Long teacherRecordId, ModelMap mmap) {
        mmap.put("teacherRecord", teacherRecordService.selectTeacherRecordById(teacherRecordId));
        return prefix + "/detail";
    }

    /**
     * 查询教师档案管理列表
     */
    @RequiresPermissions("tms:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeacherRecord teacherRecord) {
        startPage();
        List<TeacherRecord> list = teacherRecordService.selectTeacherRecordList(teacherRecord);
        return getDataTable(list);
    }

    /**
     * 导出教师档案管理列表
     */
    @RequiresPermissions("tms:record:export")
    @Log(title = "教师档案管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeacherRecord teacherRecord) {
        List<TeacherRecord> list = teacherRecordService.selectTeacherRecordList(teacherRecord);
        ExcelUtil<TeacherRecord> util = new ExcelUtil<TeacherRecord>(TeacherRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增教师档案管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存教师档案管理
     */
    @RequiresPermissions("tms:record:add")
    @Log(title = "教师档案管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeacherRecord teacherRecord) {
        return toAjax(teacherRecordService.insertTeacherRecord(teacherRecord));
    }

    /**
     * 修改教师档案管理
     */
    @GetMapping("/edit/{teacherRecordId}")
    public String edit(@PathVariable("teacherRecordId") Long teacherRecordId, ModelMap mmap) {
        TeacherRecord teacherRecord = teacherRecordService.selectTeacherRecordById(teacherRecordId);
        mmap.put("teacherRecord", teacherRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存教师档案管理
     */
    @RequiresPermissions("tms:record:edit")
    @Log(title = "教师档案管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeacherRecord teacherRecord) {
        return toAjax(teacherRecordService.updateTeacherRecord(teacherRecord));
    }

    /**
     * 删除教师档案管理
     */
    @RequiresPermissions("tms:record:remove")
    @Log(title = "教师档案管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(teacherRecordService.deleteTeacherRecordByIds(ids));
    }
}
